package com.zjw.handler.exception;


import com.zjw.annotation.domain.ResponseResult;
import com.zjw.exception.SystemException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 系统异常处理程序
 *
 * @author LKZY
 * @date 2023/12/14 16:43
 * @RestControllerAdvice注解等价于 @ControllerAdvice + @ResponseBody
 */
@RestControllerAdvice
@Slf4j
public class SystemExceptionHandler {

    @ExceptionHandler(SystemException.class)
    public ResponseResult systemExceptionHandler(SystemException e){
//        用于调试打印错误信息 {}用于站位
        log.error("自定义系统异常: {}", e);

//        封装ResponseResult对象返回
        ResponseResult res = new ResponseResult(e.getCode(), e.getMessage());
        return res;

    }
}
